import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from '@/views/login/Login.vue'

import Home  from "../views/home/Home.vue"
import Users from '../views/users/Users.vue'
import Welcome  from "../views/welcome/Welcome.vue"
// 角色列表
import Roles from "../views/roles/Roles.vue"  
// 权限列表
import Rights from "../views/rights/Rights.vue"
// 商品列表
import Goods from "../views/goods/Goods.vue"
// 添加商品
import AddGoods from "../views/addGoods/AddGoods.vue"
// 分类参数
import Params from "../views/params/Params.vue"
// 商品分类
import Categories from "../views/categories/Categories.vue"
// 订单列表
import Orders from "../views/orders/Orders.vue"
// 数据报表
import Reports from "../views/reports/Reports.vue"

Vue.use(VueRouter)

const routes = [
  { path: '/', redirect: '/login' },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: "/home",
    name: "home",
    component: Home,
    children: [
      {path: "/",redirect: "/users"},
      {
        path: "/welcome",
        name: "welcome",
        component: Welcome
      },
      {
        path: "/users",
        name: "users",
        component: Users
      },
      {
        path: "/roles",
        name: "roles",
        component: Roles
      },
      {
        path: "/rights",
        name: "rights",
        component: Rights
      },
      {
        path: "/goods",
        name: "goods",
        component: Goods,
      },
      {
        path: "/goods/add",
        name: "addGoods",
        component: AddGoods
      },
      {
        path: "/params",
        name: "params",
        component: Params
      },
      {
        path: "/categories",
        name: "categories",
        component: Categories
      },
      {
        path: "/orders",
        name: "orders",
        component: Orders
      },
      {
        path: "/reports",
        name: "reports",
        component: Reports
      },


      
      



    ]
  },
  

]

const router = new VueRouter({
  routes
})

router.beforeEach((to, from, next) =>{
  let token = localStorage.getItem("myToken")
  if (token) {
    next()
  } else {
    if (to.path == "/login") {
      next()
    } else {
      next({ path: "/login" })
    }
  }
})


export default router
